package com.uye.framework.command;

import com.uye.framework.dto.IDTO;
import com.uye.framework.exception.CommandNotReadyForExecutionException;
import com.uye.framework.exception.InternalServerException;

public abstract class BaseStatefulCommand<T extends IDTO> implements
		IStatefulCommand {

	private T model;

	public abstract void executeCommand() throws InternalServerException;

	public void checkReadyForExecution()
			throws CommandNotReadyForExecutionException {
		if (null == model) {
			throw new CommandNotReadyForExecutionException("",
					"Command's model has not been initialized.");
		}
	}

	@Override
	public final void execute() throws Exception {
		checkReadyForExecution();
		executeCommand();
	}

	public void setModel(T state) {
		this.model = state;
	}

	public T getModel() {
		return model;
	}

}
